import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import JobWantedView from '../views/JobWantedView.vue'
import transferView from '../views/transferView.vue'
import creatorView from '../views/creatorView.vue'
import bookmarkView from '../views/bookmarkView.vue'

Vue.use(VueRouter)

const routes = [{
        path: '/',
        redirect: "/home"
    },
    {
        path: '/home', //首页
        name: "home",
        component: HomeView
    },
    {
        path: '/message', //信息页
        name: 'message',
        component: () =>
            import ('../views/MesView.vue'),
        meta: {
            keep: true
        }
    },
    {
        path: '/chitchat', //聊天页
        name: 'chitchat',
        component: () =>
            import ('../views/chitchatVIew.vue')
    },
    {
        path: '/jobwant', //求职页
        name: "jobwant",
        component: JobWantedView

    },
    {
        path: '/cation', //关于页面
        name: "cation",
        component: () =>
            import ('../views/cationView.vue'),
        meta: {
            keep: true
        }
    }, {
        path: '/creator', //新建页面
        name: "creator",
        component: creatorView
    }, {
        path: '/manage', //模块管理页面
        name: "manage",
        component: () =>
            import ('../views/manageView.vue'),
    }, {
        path: '/transfer', //编辑页面
        name: "transfer",
        component: transferView

    }, {
        path: '/bookmark', //详情页面
        name: "bookmark",
        component: bookmarkView

    }, {
        path: '/order', //订单页
        name: "order",
        component: () =>
            import ('../views/orderView.vue'),
        meta: {
            keep: true
        }, // 独享路由守卫
        beforeEnter: (to, from, next) => {
            let token = window.localStorage.getItem("token");
            // 判断是否登录
            if (!token) {
                next("/loginto");
                return;
            } else {
                next();
            }
        }
    }, {
        path: '/svip', //SVIP
        name: "svip",
        component: () =>
            import ('../views/SvipView.vue'),
        meta: {
            keep: true
        }, // 独享路由守卫
        beforeEnter: (to, from, next) => {
            let token = window.localStorage.getItem("token");
            // 判断是否登录
            if (!token) {
                next("/loginto");
                return;
            } else {
                next();
            }
        }
    }, {
        path: '/curr', //广告页
        name: "curr",
        component: () =>
            import ('../views/CurriculumView.vue'),
    }, {
        path: '/allin', //导入页
        name: "allin",
        component: () =>
            import ('../views/AllInView.vue'),
    }, {
        path: '/afen', //收藏页面
        name: "afen",
        component: () =>
            import ('../views/afenView.vue'),
    }, {
        path: '/template', //选择模板页
        name: "template",
        component: () =>
            import ('../views/TemPlateView.vue'),
    }, {
        path: '/pc', //导入页
        name: "pc",
        component: () =>
            import ('../views/PCView.vue'),
    }, {
        path: '/personal', //个人中心
        name: "personal",
        component: () =>
            import ('../views/PersonalCenterView.vue')
    }, {
        path: '/atising', //广告
        name: "atising",
        component: () =>
            import ('../views/AdverTisingView.vue'),

        // 独享路由守卫
        beforeEnter: (to, from, next) => {
            console.log(to.query.id);
            let runin = to.query.id
            if (runin == 'tow') {
                next('/atisingtw')
            } else if (runin == 'one') {
                next()
            }
        }

    }, {
        path: '/atisingtw', //广告二
        name: "atisingtw",
        component: () =>
            import ('../views/AdverTisingTowView.vue'),
        meta: {
            keep: true
        }
    }, {
        path: '/settings', //个人设置
        name: "settings",
        component: () =>
            import ('../views/settingsView.vue'),
        meta: {
            keep: true
        }
    }, {
        path: '/purpose', //求职意向
        name: "purpose",
        component: () =>
            import ('../views/purposeView.vue'),
        meta: {
            keep: true
        }
    }, {
        path: '/preins', //个人中心
        name: "preins",
        component: () =>
            import ('../views/preinstallView.vue'),
        meta: {
            keep: true
        }
    }, {
        path: '/account', //个人中心二级页面
        name: "account",
        component: () =>
            import ('../views/AccountSetView.vue'),
        meta: {
            keep: true
        }
    }, {
        path: '/loginto', //登录界面
        name: "loginto",
        component: () =>
            import ('../views/logintoView.vue')
    }, {
        path: '/login', //个人中心二级页面
        name: "login",
        component: () =>
            import ('../views/loginView.vue'),
        meta: {
            keep: true
        }, // 独享路由守卫
        beforeEnter: (to, from, next) => {
            let token = window.localStorage.getItem("token");
            // 判断是否登录
            if (!token) {
                next("/loginto");
                return;
            } else {
                next();
            }
        }
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes,
    scrollBehavior() {
        return { x: 0, y: 0 }
    }
})

export default router